﻿using System.Globalization;
using UnityEngine;
using UnityEngine.UI;

public class PlayerInfosUI : BaseMono
{
	public Text LifeText;
	public Text CarryNumPlusText;
	public Text FireDisPlusText;
	public Text SpeedPlusText;

	public RectTransform TimeRect;
	public Text TimeText;

	private float time;

	public override void onStart()
	{
		base.onAwake();
		MainGame.Player.Data.OnLifeNumChange = LifeChange;
		MainGame.Player.Data.OnMoveSpeedPlusChange = SpeedPlusChange;
		MainGame.Player.Data.OnFireDisPlusChange = FireDisPlusChange;
		MainGame.Player.Data.OnCarryBombNumPlusChange = CarryNumPlusChange;

		Reset();
		base.Init();
	}

	public override void onUpdate()
	{
		base.onUpdate();
		UpdateTimeText();
	}

	public void UpdateTimeText()
	{
		if (MainGame.Ins.IsGameEnd)
		{
			return;
		}
		time -= Time.deltaTime;
		int temp = (int) time;
		temp = Mathf.Max(0, temp);

		int minute = temp/60;
		int second = temp%60;

		TimeRect.sizeDelta = new Vector2(time, 25);
		TimeText.text = minute + " : " + second;

		if (temp <= 0)
		{
			EventMgr.Ins.RaiseEvent(GameState.GameEnd, new object[] {false});
		}
	}

	public void SetVisible(bool visible)
	{
		gameObject.SetActive(visible);
	}

	public void LifeChange(int num) {
		LifeText.text = "x " + num;
	}

	public void CarryNumPlusChange(int num) {
		CarryNumPlusText.text = "x " + num;
	}

	public void FireDisPlusChange(int num) {
		FireDisPlusText.text = "x " + num;
	}

	public void SpeedPlusChange(int num) {
		SpeedPlusText.text = "x " + num;
	}

	public void Reset()
	{
		time = MainGame.Ins.CurLevelInfo.TimeLimit;
	}
}
